import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

drive = webdriver.Chrome()
drive.maximize_window()
drive.get("https://sahitest.com/demo/confirmTest.htm")
time.sleep(1)
drive.find_element(By.NAME, "b1").click()
# 使用alert.text获取弹窗的文字
print(drive.switch_to.alert.text)
time.sleep(3)
# 点击确定按钮
drive.switch_to.alert.accept()
time.sleep(2)
# 点击取消
# drive.switch_to.alert.dismiss()
# time.sleep(2)
drive.close()
